# 设置CMake的最低版本要求为3.5，如果版本低于3.5将报错
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

# 定义项目名称为"recipe-04"，并指定项目使用的编程语言为C++
project(recipe-04 LANGUAGES CXX)

# 定义一个名为"arch-dependent"的可执行文件，其源文件为arch-dependent.cpp
add_executable(arch-dependent arch-dependent.cpp)

# 根据void指针的大小判断目标架构是32位还是64位
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  # 如果是64位架构，定义宏IS_64_BIT_ARCH
  target_compile_definitions(arch-dependent PUBLIC "IS_64_BIT_ARCH")
  message(STATUS "Target is 64 bits")  # 输出日志信息
else()
  # 如果是32位架构，定义宏IS_32_BIT_ARCH
  target_compile_definitions(arch-dependent PUBLIC "IS_32_BIT_ARCH")
  message(STATUS "Target is 32 bits")  # 输出日志信息
endif()

# 检测主机处理器架构并输出相关信息
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i386")
  message(STATUS "i386 architecture detected")  # 检测到i386架构
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i686")
  message(STATUS "i686 architecture detected")  # 检测到i686架构
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
  message(STATUS "x86_64 architecture detected")  # 检测到x86_64架构
else()
  message(STATUS "host processor architecture is unknown")  # 未知架构
endif()

# 将主机处理器架构信息作为宏传递给源代码
target_compile_definitions(arch-dependent
  PUBLIC "ARCHITECTURE=${CMAKE_HOST_SYSTEM_PROCESSOR}"
  )
